#include "index.h"
#include <QPainter>
#include <QString>
#include <stdio.h>

Index::Index(int color, unsigned int index)
{
    c = color;

    sprintf(buffer, "%d", index);

    rect = new QRectF();

    setZValue(2);
}

QRectF Index::boundingRect() const
{
    return *rect;
}

QPainterPath Index::shape() const
{
    QPainterPath path;
    path.addRoundRect(*rect, 99, 99);
    return path;
}

void Index::paint(QPainter *painter,
               const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->setRenderHint(QPainter::Antialiasing, true);
    if(c == 1)
    {
        painter->setPen(QPen(Qt::white, 1, Qt::SolidLine, Qt::SquareCap));
        painter->drawText(QRectF(0,0,28,28), Qt::AlignCenter, QString(buffer));
    }
    if(c == -1)
    {
        painter->setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::SquareCap));
        painter->drawText(QRectF(0,0,28,28), Qt::AlignCenter, QString(buffer));
    }
}
